package Modellus.WinUI.ExampleTable;

import Modellus.Core.IPersister;
import Modellus.Core.Model.IModel;
import Modellus.WinUI.Commands.CopyTableCommand;
import Modellus.WinUI.LocaleInformation;
import Modellus.WinUI.ModellusMainPanel;
import Modellus.WinUI.Resource.Common.CommonResource;
import Modellus.WinUI.ExampleTable.RibbonTask.TableValuesComponent;
import Modellus.WinUI.InternalFrames.ModellusInternalFrame;
import Modellus.WinUI.Utils.ResizableBufferedImage;
import Modellus.WinUI.Utils.UI.Ribbon.ExtendedJRibbonBand;
import Modellus.WinUI.Utils.UI.Ribbon.ExtendedRibbonTask;
import Modellus.WinUI.Utils.UI.Ribbon.IExtendedJRibbonBand;
import Modellus.WinUI.Utils.UI.Ribbon.IExtendedRibbonTask;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ResourceBundle;

public class TableExampleFrame extends ModellusInternalFrame implements ITableInternalFrame
{
	protected TableUI _table;
	protected IModel _model;
	BufferedImage _bufferedImage;
	Graphics2D _bufferedImageGraphics;
	int _lastW;
	int _lastH;
	static final String TASK_TITLE = "Example";
	static ResourceBundle TableTaskBundle = LocaleInformation.instance().getBundle("Modellus/WinUI/tableTask");

	public TableExampleFrame(IModel model)
	{
		super("Example", TASK_TITLE, true);
		_table = new TableUI();
		JInternalFrame internalFrame = (JInternalFrame) _componentRepresentation;
		internalFrame.add(_table);
		internalFrame.setLayout(new GridLayout(1, 1));
		_table.setBorder(BorderFactory.createLineBorder(Color.black));
		_model = model;
		_table.setModel(_model);
		setLayer(ModellusMainPanel.WINDOWS_LAYER);
    }

	protected IExtendedRibbonTask createRibbonTasks()
	{
		IExtendedRibbonTask tableTask = new ExtendedRibbonTask(TASK_TITLE);
		IExtendedJRibbonBand tableRibbonBand = new ExtendedJRibbonBand(TableTaskBundle.getString("Table_Band_Title"));
		IExtendedJRibbonBand clipboardRibbonBand = new ExtendedJRibbonBand(TableTaskBundle.getString("Clipboard_Band_Title"));

		TableValuesComponent tableValuesComponent = new TableValuesComponent();
		tableValuesComponent.init(_table, _model);
		tableRibbonBand.addJComponent((JPanel) tableValuesComponent.getJComponent());
		clipboardRibbonBand.addJRibbonCommandButton(new ResizableBufferedImage(CommonResource.instance().getCopyImage()), TableTaskBundle.getString("Copy_Image_Button_Label"), new CopyTableCommand(_model, _table.getTable()));
        tableTask.init(tableRibbonBand, clipboardRibbonBand);
        return tableTask;
	}

	public IPersister getPersister()
	{
		return new TablePersister(this, "Table");
	}

	public void clear()
	{
		_table.clear();
	}

	public boolean getChanged()
	{
		return false;
	}

	public void setChanged(boolean changed)
	{
	}

	public TableUI getTableUI()
	{
		return _table;
	}
}


